package com.jihu.design.creatation.singleton;

/**
 * @author jihu
 * @date 2021/9/10
 */
public class Person {

    private String name;
    private String age;

    //内存可见性
    private volatile static Person person;

    //构造器私有 外部不能实例化
    private Person(){
        System.out.println("创建了person");
    }

    public static Person getInstance(){
        if(person == null){
            synchronized (Person.class){
                if(person == null){
                    person = new Person();
                }
            }
        }
        return person;
    }

}
